<?php

/**
 * AuthController
 *
 * @author Maodo DIOP <dmaodo@gmail.com>
 * @version
 */

require_once 'Zend/Controller/Action.php';
require_once 'Zend/Auth.php';
require_once 'Zend/Auth/Adapter/DbTable.php';

class MatricegmvController extends Zend_Controller_Action {


	public function indexAction()
	{
		 
		 
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//$this->view->title = "Supprimer Espece";
		//$this->view->headTitle($this->view->title);
		$matricegmv= new Model_DbTable_Matricegmv();
		$res = $matricegmv->getInfoMatricegmv();
		$resultat = Zend_Json :: encode($res);
		$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);

	}

	public function testAction()
	{
		 
		 
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//$this->view->title = "Supprimer Espece";
		//$this->view->headTitle($this->view->title);
		$matricegmv= new Model_DbTable_Matricebr();
		$res = $matricegmv->getProprietaire('1');
		$resultat = Zend_Json :: encode($res);
		//$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);

	}
	//Action pour ajouter
	public function addAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//if ($this->getRequest()->isPost()) {
			$i = $this->_getParam('i', 0);
			$j = $this->_getParam('j', 0);
			$type = stripslashes($this->_getParam('type', 0));
			$longueur = stripslashes($this->_request->getPost('longueur'));
			$taille = stripslashes($this->_request->getPost('taille'));
			$terrain = stripslashes($this->_request->getPost('terrain'));
			$proprietaire = stripslashes($this->_request->getPost('proprietaire'));
			$origine = stripslashes($this->_request->getPost('origine'));
			$espece = stripslashes($this->_request->getPost('espece'));
			$latitude = stripslashes($this->_request->getPost('latitude'));
			$longitude = stripslashes($this->_request->getPost('longitude'));
			$matricegmv = new Model_DbTable_Matricegmv();
			$matricegmv->addMatricegmv($i,$j,$type,$longueur,$taille,$terrain,$proprietaire,$origine,$espece,$latitude,$longitude);                
			//$this->_helper->redirector('index');
		//}
		
		
		

	}

public function editAction() {
		$form = new Form_Matricegmv() ;
		$form->submit->setLabel('Enregistrer');
		$this->view->form = $form;
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {            	
				$id = (int)$this->_getParam('id');
				$i = (int)$form->getValue('i');
				$j = (int)$form->getValue('j');
				$type = $form->getValue('type');     
				$longueur = $form->getValue('longueur');
				$taille = $form->getValue('taille');
				$terrain = $form->getValue('terrain');
				$proprietaire = $form->getValue('proprietaire');
				$origine = $form->getValue('origine');
				$espece = $form->getValue('espece');
				$espece = $form->getValue('latitude');
				$longitude = $form->getValue('longitude');
				
				$matricegmv = new Model_DbTable_Matricegmv();
				$matricegmv->updateMatricegmv($id, $i, $j, $type, $longueur,$taille,$terrain,$proprietaire,$origine,$espece,$latitude,$longitude);
				$res = array(); 
				$res = $matricegmv->getMatricegmv($id);        
				$this->_redirect('/matricegmv/index');
			} else {
				$form->populate($formData);
			}
		} else {
			//Si le formulaire n'est pas encore post�
			//Recuperer la valeur de l'objet � editer
			$id = $this->_request->getParam('id', 0);
			if ($idarbre > 0) {
				$matricegmv = new Model_DbTable_Matricegmv();
				$form->populate($matricegmv->getMatricegmv($id));
			}
		} 
	}


	public function deleteAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();


		$id = $this->_getParam('id', 0);
		$matricegmv = new Model_DbTable_Matricegmv();
		$matricegmv->deleteMatricegmv($id);

		$this->_redirect('/matricegmv/index');
		 
	}

	public function allmatricegmvAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//$this->view->title = "Supprimer Espece";
		//$this->view->headTitle($this->view->title);
		$matricegmv = new Model_DbTable_Matricegmv();
		$res = $matricegmv->getAllMatricegmv();
		$resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
	}
	
	public function latitudeAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//$this->view->title = "Supprimer Espece";
		//$this->view->headTitle($this->view->title);
		$matricegmv = new Model_DbTable_Matricegmv();
		$res = $arbre->getLatitude($this->_request->getParam('id', 0));
		$resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
	}
	
	public function longitudeAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//$this->view->title = "Supprimer Espece";
		//$this->view->headTitle($this->view->title);
		$matricegmv = new Model_DbTable_Matricegmv();
		$res = $arbre->getLongitude($this->_request->getParam('id', 0));
		$resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
	}

public function getcoordonneeAction()
    {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();

		/*$imin = $this->getRequest()->getPost('imin', 0);
        $imax = $this->getRequest()->getPost('imax', 0);
        $jmin = $this->getRequest()->getPost('jmin', 0);
        $jmax = $this->getRequest()->getPost('jmax', 0);*/
        
        $imin = $this->_request->getParam('imin', 0);
        $imax = $this->_request->getParam('imax', 0);
        $jmin = $this->_request->getParam('jmin', 0);
        $jmax = $this->_request->getParam('jmax', 0);
        
        $matricegmv = new Model_DbTable_Matricegmv();
        $res = $matricegmv->getCoordonneee($imin,$imax,$jmin,$jmax);
    	
        $resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
    	
    }



}

